
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(int argc, char **argv)
{
    if (argc != 2)
    {
        cout << "./a.out  xpositionFile\n"
             << endl;
        exit(EXIT_FAILURE);
    }
    // muinf =  1.7892976260350732e-05
    // cspeed =  340.2970287557621
    // velocity =  68.05940575115243
    // rho =  0.13145116433849965
    // pressure =  10873.083316062037

    double rhoInf{0.13145116433849965}, velInf{68.05940575115243},
        muInf{1.7892976260350732e-05};

    string fname{argv[1]};
    ifstream xpositionFile{fname};
    int npoint;
    xpositionFile >> npoint;
    vector<double> xpos(npoint), cf(npoint);
    for (int i = 0; i < xpos.size(); ++i)
    {
        xpositionFile >> xpos[i];
        cf[i] = 0.664 / sqrt(rhoInf * velInf * xpos[i] / muInf);
    }
    ofstream outFile{"cf.dat"};
    outFile << "TITLE = \" visualization of the cf\" \n"
            << "VARIABLES = \"x\", \"cf\"\n";
    outFile << scientific << setprecision(16);
    for (int i = 0; i < xpos.size(); ++i)
    {
        outFile << xpos[i] << "  " << cf[i] << "\n";
    }
    outFile.flush();
    outFile.close();
    xpositionFile.close();

    return 0;
}